//
//  Equation.cpp
//  Ray Tracer
//
//  Created by Kaila, Ashish on 3/24/13.
//  Copyright (c) 2013 Kaila, Ashish. All rights reserved.
//

#include "Equation.h"
#include <math.h>

std::vector<double> Equation::Evaluate(double a, double b, double c)
{
    double determinant = b * b - (4 * a * c);
    
    std::vector<double> result;
    
    // No quadratic part
    if (a == 0)
    {
        // Linear part exists
        if (b != 0)
        {
            result.push_back(-c / b);
        }
        return result;
    }

    // No solution
    if (determinant < 0)
    {
        return result;
    }
    
    double sqrtDeterminant = sqrt(determinant);
    result.push_back((-b + sqrtDeterminant) / (2 * a));
    
    // Not a unique solution
    if (determinant != 0)
    {
        result.push_back((-b - sqrtDeterminant) / (2 * a));
    }
    
    return result;
}